package com.wut.minio.controller;

import com.wut.core.common.vo.BaseResponse;
import com.wut.core.controller.BaseController;
import com.wut.minio.common.vo.MinioBucketResponse;
import com.wut.minio.service.BucketService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequiredArgsConstructor
@RequestMapping("/bucket")
@Api(tags = "Bucket模块")
public class BucketController extends BaseController {

    private final BucketService bucketService;

    @GetMapping("/exist/{bucketName}")
    @ApiOperation(value = "查看bucket是否存在")
    public BaseResponse<Boolean> checkBucketExist(@PathVariable String bucketName) {
        return BaseResponse.SUCCESS(bucketService.checkBucketExist(bucketName));
    }

    @GetMapping
    @ApiOperation(value = "获取全部bucket")
    public BaseResponse<List<MinioBucketResponse>> getBuckets() {
        return BaseResponse.SUCCESS(bucketService.getBuckets());
    }

    @PostMapping("/{bucketName}")
    @ApiOperation(value = "创建bucket")
    public BaseResponse<Boolean> createBucket(@PathVariable String bucketName) {
        return BaseResponse.SUCCESS(bucketService.createBucket(bucketName));
    }

    @DeleteMapping("/{bucketName}")
    @ApiOperation(value = "删除bucket")
    public BaseResponse<Boolean> removeBucket(@PathVariable String bucketName) {
        return BaseResponse.SUCCESS(bucketService.removeBucket(bucketName));
    }
}
